import { defineStore } from 'pinia';
// 定义创建的数据发布
interface CircleData{
  name: string;
  description: string;
  location: string;
  imageSrc: string 
}
export const useCircleStore = defineStore('circleStore', {
  state: () => ({
    circles: [] as CircleData[] //创建的那个发布收取内容
  }),
  actions: {
    addCircleData(data: CircleData) {
      this.circles.push(data);
      this.saveToStorage(); // 保存数据到本地存储
      console.log("显示数据",data);
    },
    saveToStorage() {
      try {
        wx.setStorageSync('circles', JSON.stringify(this.circles)); // 将圈子数据保存到本地存储
      } catch (error) {
        console.error('Failed to save data to storage:', error);
      }
    },
    loadFromStorage() {
      try {
        const storedData = wx.getStorageSync('circles');
        if (storedData) {
          this.circles = JSON.parse(storedData); // 从本地存储中加载数据
        }
      } catch (error) {
        console.error('Failed to load data from storage:', error);
      }
    }
  }
});
import {createPinia } from 'pinia'
import persist from 'pinia-plugin-persistedstate'
const pinia = createPinia()
pinia.use(persist)
export default pinia
export * from './modules/member'
